import Dl from '@/views/dl/dl.vue'
import Fl from '@/views/fl.vue'
import Gwc from '@/views/gwc.vue'
import Home from '@/views/home.vue'
import Ss from '@/views/ss.vue'
import Sy from '@/views/sy.vue'
import Wd from '@/views/wd.vue'
import Xq from '@/views/xq.vue'
import Zc from '@/views/zc/zc.vue'
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path:'/',
      redirect:'/zc'
    },
    {
      path: '/home',
      component: Home,
      children: [
        {
          path: 'sy',
          component: Sy,
        },
        {
          path: 'fl',
          component: Fl,
        },
        {
          path: 'gwc',
          component: Gwc,
        },
        {
          path: 'wd',
          component: Wd,
        },
        {
          path: 'ss',
          component: Ss,
        },
        {
          path: 'xq/:goods_id',
          component: Xq,
        },
      ]
    },
    {
      path: '/zc',
      component: Zc,
    },
    {
      path: '/dl',
      component: Dl,
    }
  ],
})
 router.beforeEach((to,from,next)=>{
    if(to.fullPath=='/zc'||to.fullPath=='/dl'){
      let token = localStorage.getItem('token')
      if(token){
        next()
      }
      else{
        next('/dl')
      }
    }
    else{
      next()
    }
 })
export default router
